﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class admin_cms_DoiMatKhau : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["timeout"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                string username = Session["timeout"].ToString();
                //DataTable dtcheckuser=DataAccess.ExeStoredToDataTable("select * from admin_alluser where username='"+username+"'");
                //if (dtcheckuser.Rows.Count>0)
                //{
                txttendn.Text = username;
                //}
                
            }
        }
    }
    protected void update_click(object sender, EventArgs e)
    {
        if (Session["timeout"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            string username = Session["timeout"].ToString();
            DataTable dtcheckuser = DataAccess.ExeSQLToDataTable("select * from admin_alluser where username='" + username + "'");
            if (dtcheckuser.Rows.Count > 0)
            {
                string pass = dtcheckuser.Rows[0][2].ToString();
                string id = dtcheckuser.Rows[0][0].ToString();
                if (txtmatkhau.Text == pass)
                {
                    if (txtmatkhaumoi.Text == "")
                    {
                        Label2.Text = "Mật khẩu không được để trống";
                        txtmatkhaumoi.Focus();
                    }
                    else
                    {


                        if (txtmatkhaumoi1.Text == txtmatkhaumoi.Text)
                        {
                            string sql = "update admin_alluser set username='" + txttendn.Text + "',password='" + txtmatkhaumoi1.Text + "' where id='" + id + "' ";
                            DataAccess.ExeNonSQL(sql);
                            Label3.Text = "Bạn đổi mật khẩu thành công";
                        }
                        else
                        {
                            Label2.Text = " Mật khẩu mới không trùng nhau";
                            txtmatkhaumoi.Focus();
                        }
                    }
                }
                else
                {
                    Label1.Text = "Mật khẩu cũ không chính xác";
                    txtmatkhau.Focus();
                }
            }
        }
    }
    protected void check_matkhau(object sender, EventArgs e)
    {
        txtmatkhaumoi.Text = txtmatkhau.Text;
    }
}
